package com.xiaohudie.Lambda;

/**
 * @Author xiao hu die
 * @Date 2022/1/16 18:28
 * @Version 1.0
 */

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**JAVA内置的四种接口
 * 消费型接口 Consumer<T> void accept(T t)
 * 供给型接口 Supplier<T> T get()
 * 函数型接口 Function<T,R> R apply(T t)</>
 * 断言式接口 Predicate<T> boolean test(T t)</>*/
public class FunctionalCode {
    public static void main(String[] args) {
        Con(500.0,x-> System.out.println("学习太累了,去会所花了"+x)
        );
    }
    /**消费型接口*/
  public static void Con(Double money, Consumer<Double> consumer){
        consumer.accept(money);
  }
  /**供给型接口*/
  @Test
    public void test02(){
      List<String> list =new ArrayList<>();
      list.add("a");
      list.add("b");
      list.add("c");
      List<String> list1 = filterString(list, (x) -> x.contains("a"));
      for (String s : list1) {
          System.out.println(s);
      }

  }
  public List<String> filterString(List<String> list, Predicate<String> predicate){
      List<String> list1 =new ArrayList<>();
      for (String s : list) {
          if (predicate.test(s)){
              list1.add(s);
          }
      }
      return list1;
  }

}

